/**
 * @author rxliuli
 */
function createBaseReportVue(dateTypeApiMap, headerMap, classMap) {
    return new Vue({
        el: '#app',
        data() {
            return {
                dataTypeMap: fieldFormatter.domainArchive.dataTypeMap,
                dateType: 1,
                dateNow: new Date(),
                dateColsMap: new Map(),
                data: [],
                options: {},
            }
        },
        methods: {
            async changeDataType() {
                this.data = await dateTypeApiMap.get(this.dateType).report({
                    dateNow: rx.dateFormat(this.dateNow, 'yyyy-MM-dd'),
                })
            },
            async changeDateNow(date) {
                this.dateNow = date || new Date()
                this.data = await dateTypeApiMap.get(this.dateType).report({
                    dateNow: rx.dateFormat(this.dateNow, 'yyyy-MM-dd'),
                })
            },
            refreshCharts() {
                this.dateColsMap = callDateColsMap(this.dateNow)
                const res = row2col({
                    data: this.data,
                    cols: Array.from(headerMap.keys()),
                    sorted: dateTypeMap.get(this.dateType),
                    sortedMax: callDateMax(this.dateNow, this.dateType),
                    dateType: this.dateType,
                    classMap,
                })
                const series = Object.entries(res).map(
                    ([k, v]) =>
                        new ExSerie({
                            name: headerMap.get(k),
                            data: v,
                            type: 'bar',
                        }),
                )
                this.options = new ExOptions({
                    title: {
                        text: '报表统计',
                    },
                    legend: {
                        //单列分类
                        data: Array.from(headerMap.values()),
                    },
                    xAxis: {
                        //列标题（动态）
                        data: this.dateColsMap.get(this.dateType),
                    },
                    //行数据（动态）
                    series: Array.from(series.values()),
                })
            },
        },
        watch: {
            data() {
                this.refreshCharts()
            },
        },
        computed: {
            fieldFormatter() {
                return fieldFormatter
            },
        },
        async mounted() {
            await this.changeDataType()
        },
    })
}